package com.cskaoyan.day18;

import java.io.*;

public class TxtCount {
    public static void main(String[] args) {
        int odd = 0;
        int even = 0;
        int num = 0;
        try (BufferedInputStream in = new BufferedInputStream(new FileInputStream("a.txt"));
             BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("a.txt",true))) {
            while ((num = in.read()) != -1) {
                if (num % 2 != 0) {
                    odd++;
                } else {
                    even++;
                }
            }
            out.write(System.lineSeparator().getBytes());
            out.write(("奇数个数:" + odd + "个").getBytes());
            out.write(System.lineSeparator().getBytes());
            out.write(("偶数个数:" + even + "个").getBytes());

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
